
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.UserBalance;
import com.shop.cloud.mall.admin.service.UserBalanceService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 用户余额
 *
 * @author
 * @date 2023-11-01 09:47:36
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/userbalance")
@Tag(description = "userbalance", name = "用户余额管理")
public class UserBalanceController {

    private final UserBalanceService userBalanceService;

    /**
     * 用户余额分页列表
     * @param page 分页对象
     * @param userBalance 用户余额
     * @return
     */
    @Operation(summary = "用户余额分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:userbalance:index')")
    public R getPage(Page page, UserBalance userBalance) {
        return R.ok(userBalanceService.page(page, Wrappers.query(userBalance)));
    }

    /**
     * 用户余额查询
     * @param userId
     * @return R
     */
    @Operation(summary = "用户余额查询")
    @GetMapping("/{userId}")
    @PreAuthorize("@ato.hasAuthority('mall:userbalance:get')")
    public R getById(@PathVariable("userId") String userId) {
        return R.ok(userBalanceService.getById(userId));
    }

    /**
     * 用户余额修改
     * @param userBalance 用户余额
     * @return R
     */
    @Operation(summary = "用户余额修改")
    @SysLog("修改用户余额")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:userbalance:edit')")
    public R updateById(@RequestBody UserBalance userBalance) {
        return R.ok(userBalanceService.updateById(userBalance));
    }

}
